#include "Proxy.h"

#include <iostream>
using namespace std;

void MySystem::run()
{
    cout << "MySystem start" << endl;
}

MySystemProxy::MySystemProxy(string username, string password)
{
    cout << "MySystemProxy::MySystemProxy(string username, string password)" << endl;
    _userName = username;
    _password = password;
    _pMySystem = new MySystem();
}

bool MySystemProxy::checkUserNameAndPassword()
{
    cout << "bool MySystemProxy::checkUserNameAndPassword()" << endl;
    if (_userName == "admin" && _password == "admin") {
        return true;
    }

    return false;
}

void MySystemProxy::run()
{
    cout << "MySystemProxy::run()" << endl;
    if (checkUserNameAndPassword()) {
        cout << "success" << endl;
        _pMySystem->run();
    } else {
        cout << "failed" << endl;
    }
}

MySystemProxy::~MySystemProxy()
{
    cout << "MySystemProxy::~MySystemProxy()" << endl;
    if (_pMySystem) {
        delete _pMySystem;
        _pMySystem = nullptr;
    }
}